package com.w7vm.menuweb.managerBean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.w7vm.menuweb.entity.BeneficioMsgSy;
import com.w7vm.menuweb.entity.FormaPagamentoSy;
import com.w7vm.menuweb.entity.PlanoSy;
import com.w7vm.menuweb.facade.ContratoFacade;
import com.w7vm.menuweb.facade.PlanoFacade;
import com.w7vm.menuweb.service.ContratoService;
import com.w7vm.menuweb.vo.PlanoVO;

@ManagedBean
@ViewScoped
public class PlanoMB implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private PlanoVO planoVO;
	
	@EJB
	private PlanoFacade planoEJB;
	
	@EJB
	private ContratoFacade contratoEJB;
	
	private List<PlanoVO> planoL = null;

	
	
	/*
	 * ================================== METHOD LOAD PLANO================================================ 
	 * - ENTITY :: PLANOSY -
	 * - FACADE :: PLANOFACADE
	 * ==========================================================================================================
	 */

	public List<PlanoVO> loadPlanosAtivo() {
		System.out.println("[METHOD][loadPlanosAtivo]");
		String[] vetColorPanel = new String[20];
		List<PlanoSy> planoL1 = new ArrayList<PlanoSy>();
		List<BeneficioMsgSy> beneficioMsgL = new ArrayList<BeneficioMsgSy>();
		BeneficioMsgSy beneficioObj = new BeneficioMsgSy();
		ContratoService contratoService = new ContratoService();
		int i = 0;

		// Vetor de Cores
		vetColorPanel[0] = "#FFE7BA";
		vetColorPanel[1] = "#EED8AE";
		vetColorPanel[2] = "#CDBA96";
		vetColorPanel[3] = "#8B7E66";

		planoL = new ArrayList<PlanoVO>();

		planoL1 = planoEJB.preparaListaPlanoAtivos();
		beneficioMsgL = contratoEJB.preparaListaBeneficioMsg();

		for (BeneficioMsgSy obj : beneficioMsgL) {
			beneficioObj.setBeneficioQtdCardapio(obj.getBeneficioQtdCardapio());
			beneficioObj.setBeneficioQtdFilial(obj.getBeneficioQtdFilial());
			beneficioObj.setBeneficioQtdMesTermino(obj.getBeneficioQtdMesTermino());
		}

		for (PlanoSy obj : planoL1) {
			planoVO = new PlanoVO();

			planoVO.setIdPlanoSys(obj.getIdPlanoSys());
			planoVO.setNomePlano(obj.getNomePlano());
			planoVO.setDescricao(obj.getDescricao());

			planoVO.setCorPanelPlano(vetColorPanel[i]);

			planoVO.setPeriodicidadeTempo(obj.getPeriodicidadeTempo());
			planoVO.setPeriodicidadeTipoFormatado("/" + obj.getPeriodicidadeTempo());
			
			planoVO.setMoeda(obj.getMoeda());
			planoVO.setBenQtdeCardapio(obj.getBenQtdeCardapio());
			planoVO.setBenQtdeFilial(obj.getBenQtdeFilial());
			planoVO.setBenPeriodoAssinatura(obj.getBenPeriodoAssinatura());
			planoVO.setBeneficioTexto(obj.getBeneficioTexto());

			String benQtdeCardapioS = Integer.toString(planoVO.getBenQtdeCardapio())+ " "+ beneficioObj.getBeneficioQtdCardapio();
			planoVO.setBeneficioQtdeCardapioS(benQtdeCardapioS);

			String benQtdeFilialS = Integer.toString(planoVO.getBenQtdeFilial())+ " "+ beneficioObj.getBeneficioQtdFilial();
			planoVO.setBeneficioQtdeFilialS(benQtdeFilialS);

			String benPeriodoAssinaturaS = Integer.toString(planoVO.getBenPeriodoAssinatura())+ " "+ beneficioObj.getBeneficioQtdMesTermino();
			planoVO.setBeneficioPeriodoAssinaturaS(benPeriodoAssinaturaS);

			planoVO.setValor(contratoService.converterDoubleDoisDecimais(obj.getValor()));
			
			planoL.add(planoVO);

			System.out.println("TESTTTTTTTTTTTTTTTTTTTTTTTTTTTT" + i);
			System.out.println("TESTTTTTTTTTTTTTTTTTTTTTTTTTTTT"+ vetColorPanel[i]);

			i = i + 1;
		}
		return planoL;
	}
	


	
	
	/*
	 *************************************************************************************************************************
	 * METHOD - SET / GET
	 *************************************************************************************************************************
	 */
	
	public List<PlanoVO> getPlanoL() {
		if (planoL == null)
			loadPlanosAtivo();
		return planoL;
	}

}
